package com.xzz.finger;

import java.util.Stack;

/**
 * @author: hhz
 * @create: 2022-02-15 09:47
 * 剑指 Offer 09. 用两个栈实现队列
 **/
public class CQueue {
    Stack<Integer> s1 = new Stack<>();
    Stack<Integer> s2 = new Stack<>();
    public CQueue() {

    }

    public void appendTail(int value) {
        s2.push(value);
    }

    public int deleteHead() {
        if(s1.empty()){
            while (!s2.empty()){
                s1.push(s2.pop());
            }
        }
        if(s1.empty()){
            return -1;
        }else {
            return s1.pop();
        }
    }

    public static void main(String[] args) {
        CQueue cQueue = new CQueue();
        cQueue.appendTail(3);
        System.out.println(cQueue.deleteHead());
        System.out.println(cQueue.deleteHead());
    }
}
